%{
 #include <ctype.h>
 #include <signal.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "out.h"
 #include <assert.h>
struct expr_t {
 short typ;
 int64_t val;
};
typedef struct expr_t expr_t;
struct item_t {
 struct item_t *
  i_next;
 short i_type;
 int64_t i_valu;
 char *i_name;
};
struct common_t {
 struct common_t *
  c_next;
 struct item_t *c_it;
 int64_t c_size;
};
typedef struct common_t common_t;
typedef struct item_t item_t;
struct sect_t {
 short s_flag;
 long s_base;
 long s_size;
 long s_comm;
 long s_zero;
 long s_lign;
 long s_foff;
 item_t *s_item;
 long s_gain;
};
typedef struct sect_t sect_t;
extern short pass ;
extern short peekc;
extern short unresolved;
extern long lineno;
extern short hllino;
extern short nerrors;
extern short sflag ;
extern char *progname;
extern char *modulename;
extern common_t *commons;
extern short uflag;
extern short dflag;
extern int64_t relonami;
extern short bflag;
extern char *aoutpath ;
extern FILE *input;
extern FILE *tempfile;
extern char *stringbuf;
extern int stringlen;
extern sect_t sect[64];
extern sect_t *DOTSCT;
extern long DOTVAL;
extern short DOTTYP;
extern unsigned short nname;
extern item_t *hashtab[(2*307)];
extern short hashindex;
extern item_t *last_it;
void item_set_nami(item_t *ip, unsigned short nami);
unsigned short item_get_nami(item_t *ip);
extern item_t *fb_ptr[4*10];
extern int nbits;
extern int bitindex;
extern short listmode;
extern short listtemp;
extern short listflag;
extern short listcolm;
extern short listeoln ;
extern FILE *listfile;
extern item_t keytab[];
extern struct outhead outhead;
extern int curr_token;
int yyparse(void);
NORETURN void stop(void);
void newmodule(char *);
int yylex(void);
void putval(int);
int getval(int);
int nextchar(void);
int hash(const char *);
item_t *item_search(const char *);
void item_insert(item_t *, int);
item_t *item_alloc(int);
item_t *fb_alloc(int);
item_t *fb_shift(int);
void newequate(item_t *, int);
void newident(item_t *, int);
void newlabel(item_t *);
void newsect(item_t *);
void newbase(int64_t);
void newcomm(item_t *, int64_t);
void switchsect(int);
void align(int64_t);
void newrelo(int, int);
long new_string(const char *);
void newsymb(const char *, int, int, int64_t);
int64_t load(const item_t *);
int store(item_t *, int64_t);
char *remember(char *);
int combine(int, int, int);
int printx(int, int64_t);
void listline(int);
int small(int, int);
void emit1(int);
void emit2(int);
void emit4(long);
void emitx(int64_t, int);
void emit8(int64_t);
void emitstr(int);
void emitf(int size, int negative);
void yyerror(const char *);
void nosect(void);
NORETURN void fatal(const char *, ...);
void serror(const char *, ...);
void warning(const char *, ...);
void nofit(void);
extern int co_id;
extern int mrg_1,mrg_2;
extern expr_t exp_1,exp_2;
extern int64_t rel_1,rel_2;
extern int model;
extern int curr_instr;
extern int eamode[];
void ea_1(int sz, int bits);
void ea_2(int sz, int bits);
void indexmode(int hibyte);
void checksize(int sz, int bits);
void test68010(void);
void badoperand(void);
void shift_op(int opc, int sz);
void bitop(int opc);
void add(int opc, int sz);
void and(int opc, int sz);
int to_dreg(int opc, int sz, int bits);
int from_dreg(int opc, int sz, int bits);
void cmp(int sz);
void move(int sz);
void move_special(int sz);
int reverse(int regs, int max);
void movem(int dr, int sz, int regs);
void movep(int sz);
void branch(int opc, expr_t exp);
void ea5x73(int rg, int sz);
void ea707172(int sz);
void ea6x(int rg, int ir, int sz);
void ea72(void);
void ea73(int ri, int sz);
void Xnofit(void);
void fbranch(int opc, expr_t exp);
void ch_sz_dreg(int size, int mode);
void check_fsize(int sz, int size);
static item_t *o_it;
%}
%union {
 short y_word;
 int64_t y_valu;
 expr_t y_expr;
 item_t *y_item;
};
%token STRING
%token <y_item> IDENT
%token <y_item> FBSYM
%token <y_valu> CODE1
%token <y_valu> CODE2
%token <y_valu> CODE4
%token NUMBER0
%token NUMBER1
%token NUMBER2
%token NUMBER3
%token NUMBER4
%token <y_valu> NUMBER8
%token NUMBERF
%token DOT
%token EXTERN
%token <y_word> DATA
%token DATA8
%token <y_word> DATAF
%token <y_word> ASCII
%token SECTION
%token COMMON
%token BASE
%token SYMB
%token SYMD
%token ALIGN
%token ASSERT
%token SPACE
%token SEEK
%token <y_word> LINE
%token FILe
%token <y_word> LIST
%left OP_OO
%left OP_AA
%left '|'
%left '^'
%left '&'
%left OP_EQ OP_NE
%left '<' '>' OP_LE OP_GE
%left OP_LL OP_RR
%left '+' '-'
%left '*' '/' '%'
%nonassoc '~'
%type <y_valu> absexp optabs1 optabs2
%type <y_expr> expr
%type <y_item> id_fb
%token <y_word> SIZE
%token <y_word> DREG
%token <y_word> AREG
%token <y_word> PC
%token <y_word> CREG
%token <y_word> SPEC
%token <y_word> ABCD
%token <y_word> ADDX
%token <y_word> ADD
%token <y_word> AND
%token <y_word> BITOP
%token <y_word> SHIFT
%token <y_word> SZ_EA
%token <y_word> OP_EA
%token <y_word> OP_NOOP
%token <y_word> OP_EA_D
%token <y_word> LEA
%token <y_word> DBR
%token <y_word> BR
%token <y_word> CMP
%token <y_word> MOVE
%token <y_word> MOVEP
%token <y_word> MOVEM
%token <y_word> MOVEC
%token <y_word> MOVES
%token <y_word> SWAP
%token <y_word> LINK
%token <y_word> UNLK
%token <y_word> TRAP
%token <y_word> STOP
%token <y_word> EXG
%token <y_word> OP_EXT
%token <y_word> RTD
%token <y_word> MODEL
%token <y_word> FPCR
%token <y_word> FPREG
%token <y_word> FMOVE
%token <y_word> FMOVECR
%token <y_word> FMOVEM
%token <y_word> FDYADIC
%token <y_word> FMONADIC
%token <y_word> FSINCOS
%token <y_word> FBCC
%token <y_word> FDBCC
%token <y_word> FNOP
%token <y_word> FSCC
%token <y_word> FTST
%token <y_word> FSAVRES
%token <y_word> FTRAPCC
%token <y_word> FSIZE
%token <y_word> CP
%type <y_word> bcdx op_ea regs rrange
%type <y_word> reg sizedef sizenon creg
%type <y_word> fsize fregs fcregs frlist frrange
%%
program :
 | program IDENT ':'
   { newident($2, DOTTYP); newlabel($2);}
 | program NUMBER8 ':'
   { if ($2 < 0 || $2 > 9) {
     serror("bad f/b label");
     $2 = 0;
    }
    newlabel(fb_shift((int)$2));
   }
 | program CODE1
   { emit1((int)$2); if (listflag) listline(0); else if (listtemp) { listflag = listtemp; listeoln = 1; };}
 | program CODE2
   { emit2((int)$2); if (listflag) listline(0); else if (listtemp) { listflag = listtemp; listeoln = 1; };}
 | program CODE4
   { emit4((long)$2); if (listflag) listline(0); else if (listtemp) { listflag = listtemp; listeoln = 1; };}
 | program operation ';'
 | program operation '\n'
   { lineno++; if (listflag) listline(1); else if (listtemp) { listflag = listtemp; listeoln = 1; }; assert(relonami == 0);}
 | program '#' NUMBER8 STRING '\n'
   { lineno = $3;
    if (modulename) strncpy(modulename, stringbuf, 200 -1);
    if (listflag) listline(1); else if (listtemp) { listflag = listtemp; listeoln = 1; }; assert(relonami == 0);
   }
 | program error '\n'
   { serror("syntax error"); yyerrok;
    lineno++; if (listflag) listline(1); else if (listtemp) { listflag = listtemp; listeoln = 1; }; assert(relonami == 0);
   }
 ;
operation
 :
 | IDENT '=' expr
   {
    if (listflag & 1)
     listcolm += printx(8, $3.val);
    newequate($1, $3.typ);
    store($1, $3.val);
   }
 | LIST
   { if ($1)
     listtemp = listmode;
    else if ((dflag & 01000) == 0)
     listtemp = 0;
   }
 | SECTION IDENT
   { newsect($2);}
 | COMMON IDENT ',' absexp
   { newcomm($2, $4);}
 | BASE absexp
   { if (pass == 0) newbase($2);}
 | ASSERT expr
   { if ($2.val == 0 && pass == 2)
     warning("assertion failed");
   }
 | SYMB STRING ',' expr { o_it = last_it; }
  optabs2 optabs2
   { if ((sflag & 010) && (pass != 0)) {
     if (
      pass == 2
      &&
      ($4.typ & S_TYP) == S_UND
        ) {
      serror("expression undefined");
      relonami = -1;
     }
     if (
      (pass != 0)
      &&
      ($4.typ & S_COM)
        ) {
      $4.typ = S_CRS;
      $4.val = new_string(o_it->i_name);
      relonami = 0;
     }
     newsymb(
      *stringbuf ? stringbuf : (char *) 0,
      (short)(
       ($4.typ & (S_EXT|S_TYP))
       |
       ((unsigned short)$6<<8)
      ),
      (short)$7,
      $4.val
     );
    }
   }
 | SYMD STRING ',' absexp ',' absexp
   { if ((sflag & 010) && (pass != 0)) {
     newsymb(
      *stringbuf ? stringbuf : (char *) 0,
      (short)(
       (DOTTYP & (S_EXT|S_TYP))
       |
       ((unsigned short)$4<<8)
      ),
      (short)$6,
      (int64_t)DOTVAL
     );
    }
   }
 | LINE optabs1
   { if ((sflag & 020) && (pass != 0)) {
     if ($2)
      hllino = (short)$2;
     else
      hllino++;
     newsymb(
      (char *)0,
      (DOTTYP | S_LIN),
      hllino,
      (int64_t)DOTVAL
     );
    }
   }
 | FILe STRING
   { if ((sflag & 020) && (pass != 0)) {
     hllino = 0;
     newsymb(
      stringbuf,
      (DOTTYP | S_FIL),
      0,
      (int64_t)DOTVAL
     );
    }
   }
 | EXTERN externlist
 | ALIGN optabs1
   { align($2);}
 | SPACE absexp
   { if (DOTSCT == NULL)
     nosect();
    DOTVAL += $2;
    DOTSCT->s_zero += $2;
   }
 | SEEK absexp
   { if (DOTSCT == NULL)
     nosect();
    if ($2 < DOTVAL)
     serror("cannot move location counter backwards");
    if (pass == 0)
     DOTSCT->s_flag |= 2;
    DOTSCT->s_zero += $2 - DOTVAL;
    DOTVAL = $2;
   }
 | DATA datalist
 | DATA8 data8list
 | DATAF dataflist
 | ASCII STRING
   { emitstr($1);}
 ;
externlist
 : IDENT
   { $1->i_type |= S_EXT;}
 | externlist ',' IDENT
   { $3->i_type |= S_EXT;}
 ;
datalist
 : expr
   {
    if (1 != 0 && (pass != 0))
     newrelo($1.typ, (int)$<y_word>0|(RELBR|RELWR));
    emitx($1.val, (int)$<y_word>0);
   }
 | datalist ',' expr
   {
    if (1 != 0 && (pass != 0))
     newrelo($3.typ, (int)$<y_word>0|(RELBR|RELWR));
    emitx($3.val, (int)$<y_word>0);
   }
 ;
data8list
 : absexp
   { emit8($1);}
 | data8list ',' absexp
   { emit8($3);}
 ;
numberf
 : NUMBERF
   {
    emitf((int)$<y_word>-1, 0);
   }
 | '-' NUMBERF
   {
    emitf((int)$<y_word>-1, 1);
   }
 ;
dataflist
 : numberf
 | dataflist ',' numberf
 ;
expr : error
   { serror("expr syntax err");
    $$.val = 0; $$.typ = S_UND;
   }
 | NUMBER8
   { $$.val = $1;
    $$.typ = S_ABS;
   }
 | id_fb
   { $$.val = load($1);
    last_it = $1;
    $$.typ = $1->i_type & ~S_EXT;
   }
 | STRING
   { if (stringlen != 1)
     serror("too many chars");
    $$.val = stringbuf[0];
    $$.typ = S_ABS;
   }
 | '[' expr ']'
   { $$ = $2;}
 | expr OP_OO expr
   { $$.val = ($1.val || $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr OP_AA expr
   { $$.val = ($1.val && $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr '|' expr
   { $$.val = ($1.val | $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr '^' expr
   { $$.val = ($1.val ^ $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr '&' expr
   { $$.val = ($1.val & $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr OP_EQ expr
   { $$.val = ($1.val == $3.val);
    $$.typ = combine($1.typ, $3.typ, '>');
   }
 | expr OP_NE expr
   { $$.val = ($1.val != $3.val);
    $$.typ = combine($1.typ, $3.typ, '>');
   }
 | expr '<' expr
   { $$.val = ($1.val < $3.val);
    $$.typ = combine($1.typ, $3.typ, '>');
   }
 | expr '>' expr
   { $$.val = ($1.val > $3.val);
    $$.typ = combine($1.typ, $3.typ, '>');
   }
 | expr OP_LE expr
   { $$.val = ($1.val <= $3.val);
    $$.typ = combine($1.typ, $3.typ, '>');
   }
 | expr OP_GE expr
   { $$.val = ($1.val >= $3.val);
    $$.typ = combine($1.typ, $3.typ, '>');
   }
 | expr OP_RR expr
   { $$.val = ($1.val >> $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr OP_LL expr
   { $$.val = ($1.val << $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr '+' expr
   { $$.val = ($1.val + $3.val);
    $$.typ = combine($1.typ, $3.typ, '+');
   }
 | expr '-' expr
   { $$.val = ($1.val - $3.val);
    $$.typ = combine($1.typ, $3.typ, '-');
   }
 | expr '*' expr
   { $$.val = ($1.val * $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr '/' expr
   { if ($3.val == 0) {
     if (pass == 2)
      serror("divide by zero");
     $$.val = 0;
    } else
     $$.val = ($1.val / $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | expr '%' expr
   { if ($3.val == 0) {
     if (pass == 2)
      serror("divide by zero");
     $$.val = 0;
    } else
     $$.val = ($1.val % $3.val);
    $$.typ = combine($1.typ, $3.typ, 0);
   }
 | '+' expr %prec '*'
   { $$.val = $2.val;
    $$.typ = combine(S_ABS, $2.typ, 0);
   }
 | '-' expr %prec '*'
   { $$.val = -$2.val;
    $$.typ = combine(S_ABS, $2.typ, 0);
   }
 | '~' expr
   { $$.val = ~$2.val;
    $$.typ = combine(S_ABS, $2.typ, 0);
   }
 | DOT
   { $$.val = DOTVAL;
    $$.typ = DOTTYP|0x0400;
   }
 ;
id_fb : IDENT
 | FBSYM
 ;
absexp : expr
   { if (($1.typ & ~S_EXT) != S_ABS)
     serror("must be absolute");
    $$ = $1.val;
   }
 ;
optabs1
 :
   { $$ = 0;}
 | absexp
   { $$ = $1;}
 ;
optabs2
 :
   { $$ = 0;}
 | ',' absexp
   { $$ = $2;}
 ;
operation
 : { curr_instr = curr_token; }
  _operation
 ;
_operation
 : bcdx DREG ',' DREG
   { emit2($1 | $2 | $4<<9);}
 | bcdx '-' '(' AREG ')' ',' '-' '(' AREG ')'
   { emit2($1 | $4 | $9<<9 | 010);}
 | ADD sizedef ea_ea
   { add($1, $2);}
 | AND sizenon ea_ea
   { and($1, $2);}
 | SHIFT sizedef ea_ea
   { shift_op($1, $2);}
 | BR expr
   { branch($1, $2);}
 | DBR DREG ',' expr
   { $4.val -= (DOTVAL+2);
    if (!((((($4.val) + 0x8000L) & ~0xFFFFL) == 0))) Xnofit();;
    emit2($1 | $2);
    newrelo($4.typ, RELPC|RELO2|RELBR|RELWR);
    emit2(((int)($4.val) & 0xFFFF));
   }
 | BITOP ea_ea
   { bitop($1);}
 | OP_EA_D sizedef ea ',' DREG
   { if ($2 != 0100) {
     serror("illegal size");
    }
    emit2($1 | mrg_2 | $5<<9);
    ea_2(0100, 0x01);
   }
 | LEA ea ',' AREG
   { emit2(040700 | mrg_2 | $4<<9);
    ea_2(0200, 0x04);
   }
 | op_ea ea
   { emit2(($1&0177700) | mrg_2);
    ea_2($1&0300, $1&017);
   }
 | OP_NOOP
   { emit2($1);}
 | CMP sizedef ea_ea
   { cmp($2);}
 | MOVE sizenon ea_ea
   { move($2);}
 | MOVEP sizedef ea_ea
   { movep($2);}
 | MOVEM sizedef regs ',' notimmreg
   { movem(0, $2, $3);}
 | MOVEM sizedef notimmreg ',' regs
   { movem(1, $2, $5);}
 | MOVES sizedef ea_ea
   { test68010();
    if (mrg_1 <= 017) {
     emit2(007000 | $2 | mrg_2);
     emit2(mrg_1 << 12 | 04000);
     ea_2($2,0x08|0x02);
    } else if (mrg_2 <= 017) {
     emit2(007000 | $2 | mrg_1);
     emit2(mrg_2 << 12);
     ea_1($2,0x08|0x02);
    } else
     badoperand();
   }
 | MOVEC creg ',' reg
   { test68010();
    emit2(047172); emit2($2 | $4<<12);
   }
 | MOVEC reg ',' creg
   { test68010();
    emit2(047173); emit2($4 | $2<<12);
   }
 | EXG reg ',' reg
   { if (($2 & 010) == 0)
     emit2(
      (0140500|$4|$2<<9)
      +
      (($4&010)<<3)
     );
    else
     emit2(
      (0140610|$2|($4&07)<<9)
      -
      (($4&010)<<3)
     );
   }
 | OP_EXT sizedef DREG
   { checksize($2, 2|4); emit2(044000 | $2+0100 | $3);}
 | SWAP DREG
   { emit2(044100 | $2);}
 | STOP imm
   { emit2($1); ea_2(0100, 0);}
 | LINK AREG ',' imm
   { emit2(047120 | $2); ea_2(0100, 0);}
 | UNLK AREG
   { emit2(047130 | $2);}
 | TRAP '#' absexp
   { if (!(((($3) & ~((int)017)) == 0))) Xnofit();; emit2(047100|((short)($3) & 017));}
 | RTD imm
   { test68010();
    emit2(047164);
    ea_2(0100, 0);
   }
 | MODEL
   { model = $1;}
 | fp_op
 ;
bcdx : ABCD
 | ADDX sizedef
   { $$ = $1 | $2;}
 ;
creg : CREG
 | SPEC { if ($1 != 075) badoperand(); $$ = 04000;}
 ;
op_ea : OP_EA
 | SZ_EA sizedef
   { $$ = $1 | $2;}
 ;
regs : rrange
 | regs '/' rrange
   { $$ = $1 | $3;}
 ;
rrange : reg
   { $$ = 1<<$1;}
 | reg '-' reg
   { if ($1 > $3)
     badoperand();
    for ($$ = 0; $1 <= $3; $1++)
     $$ |= (1<<$1);
   }
 ;
ea : DREG
   { mrg_2 = $1;}
 | AREG
   { mrg_2 = 010 | $1;}
 | SPEC
   { mrg_2 = $1;}
 | notimmreg
 | imm
 ;
notimmreg
 : '(' AREG ')'
   { mrg_2 = 020 | $2;}
 | '(' AREG ')' '+'
   { mrg_2 = 030 | $2;}
 | '-' '(' AREG ')'
   { mrg_2 = 040 | $3;}
 | expr sizenon
   { exp_2 = $1; ea707172($2);
    {rel_2 = relonami; relonami = 0;};
   }
 | expr '(' reg sizenon ')'
   { exp_2 = $1; ea5x73($3, $4);
    {rel_2 = relonami; relonami = 0;};
   }
 | expr '(' AREG ',' reg sizedef ')'
   { exp_2 = $1; ea6x($3, $5, $6);
    {rel_2 = relonami; relonami = 0;};
   }
 | expr '(' PC ')'
   { exp_2 = $1; ea72();
    {rel_2 = relonami; relonami = 0;};
   }
 | expr '(' PC ',' reg sizedef ')'
   { exp_2 = $1; ea73($5, $6);
    {rel_2 = relonami; relonami = 0;};
   }
 ;
imm : '#' expr
   { mrg_2 = 074; exp_2 = $2;
    {rel_2 = relonami; relonami = 0;};
   }
 ;
reg : DREG
 | AREG
   { $$ = $1 | 010;}
 ;
sizedef :
   { $$ = 0100;}
 | SIZE
 ;
sizenon :
   { $$ = 0300;}
 | SIZE
 ;
ea_ea : ea ','
   { mrg_1 = mrg_2; exp_1 = exp_2;
    {rel_1 = rel_2; rel_2 = 0;};
   }
  ea
 ;
fp_op : CP
   { co_id = $1; }
  fp_op1
 | { co_id = 01000; }
  fp_op1
 ;
fp_op1 : FMOVE fsize ea ',' FPCR
   { check_fsize($2, 00);
    if ((mrg_2&070) == 010 && $5 != 001)
     badoperand();
    emit2((0170000|co_id|mrg_2));
    emit2((0100000|($5<<10)));
    ea_2(0200, 0);
   }
 | FMOVE fsize FPCR ',' ea
   { check_fsize($2, 00);
    if ((mrg_2&070) == 010 && $3 == 001)
     badoperand();
    emit2((0170000|co_id|mrg_2));
    emit2((0120000|($3<<10)));
    ea_2(0200, 0x08);
   }
 | FMOVE fsize FPREG ',' FPREG
   { emit2(0170000|co_id);
    emit2(($3<<10)|($5<<7));
   }
 | FMOVE fsize ea ',' FPREG
   { ch_sz_dreg($2, mrg_2&070);
    emit2((0170000|co_id|mrg_2));
    emit2((0040000|($2<<10)|($5<<7)));
    ea_2(0200, 0x01);
   }
 | FMOVE fsize FPREG ',' ea
   { ch_sz_dreg($2, mrg_2&070);
    if ($2 == 03)
     serror("packed decimal needs k-factor");
    emit2((0170000|co_id|mrg_2));
    emit2((0060000|($2<<10)|($3<<7)));
    ea_2(0200, 0x01|0x08);
   }
 | FMOVE fsize FPREG ',' ea '{' '#' absexp '}'
   { check_fsize($2, 03);
    if (!(((((($8)+64) & ~((int)0177)) == 0)))) nofit();
    emit2((0170000|co_id|mrg_2));
    emit2((0066000|($3<<7)|((short)($8) & 0177)));
    ea_2(0200, 0x02|0x01|0x08);
   }
 | FMOVE fsize FPREG ',' ea '{' DREG '}'
   { check_fsize($2, 03);
    emit2((0170000|co_id|mrg_2));
    emit2((0076000|($3<<7)|($7<<4)));
    ea_2(0200, 0x02|0x01|0x08);
   }
 | FMOVECR fsize '#' absexp ',' FPREG
   { if (!(((($4) & ~((int)0177)) == 0))) nofit();
    check_fsize($2, 02);
    emit2(0170000|co_id);
    emit2(056000|($6<<7)|((short)($4) & 0177));
   }
 | FMOVEM FSIZE fregs ',' notimmreg
   { check_fsize($2, 02);
    if ((mrg_2&070) == 030)
     serror("bad addressing category");
    emit2((0170000|co_id|mrg_2));
    emit2(0160000 |
     (((mrg_2&070)==040 || ($3&04000)) ?
      $3 :
      (010000|reverse($3,8))));
    ea_2(0200, 0x02|0x08);
   }
 | FMOVEM FSIZE notimmreg ',' fregs
   { check_fsize($2, 02);
    if ((mrg_2&070) == 040)
     serror("bad addressing category");
    emit2((0170000|co_id|mrg_2));
    emit2((0150000|(($5&04000)?$5:reverse($5,8))));
    ea_2(0200, 0x02);
   }
 | FMOVEM SIZE fcregs ',' ea
   { checksize($2, 4);
    if ((mrg_2&070) == 1 && $3!= 02000)
     serror("bad addressing category");
    if ((mrg_2 & 070) == 0 &&
        $3 != 02000 && $3 != 04000 && $3 != 010000)
     serror("bad addressing category");
    emit2((0170000|co_id|mrg_2));
    emit2((0120000|$3));
    ea_2(0200, 0x08);
   }
 | FMOVEM SIZE ea ',' fcregs
   { checksize($2, 4);
    if ((mrg_2&070) == 1 && $5!= 02000)
     serror("bad addressing category");
    if ((mrg_2 & 070) == 0 &&
        $5 != 02000 && $5 != 04000 && $5 != 010000)
     serror("bad addressing category");
    emit2((0170000|co_id|mrg_2));
    emit2((0100000|$5));
    ea_2(0200, 0);
   }
 | FDYADIC fsize ea ',' FPREG
   { emit2((0170000|co_id|mrg_2));
    emit2((0040000|($2<<10)|($5<<7)|$1));
    ch_sz_dreg($2, mrg_2&070);
    ea_2(0200, 0x01);
   }
 | FDYADIC fsize FPREG ',' FPREG
   { check_fsize($2, 02);
    emit2(0170000|co_id);
    emit2(($3<<10)|($5<<7)|$1);
   }
 | FMONADIC fsize ea ',' FPREG
   { emit2((0170000|co_id|mrg_2));
    emit2((0040000|($2<<10)|($5<<7)|$1));
    ch_sz_dreg($2, mrg_2&070);
    ea_2(0200, 0x01);
   }
 | FMONADIC fsize FPREG ',' FPREG
   { check_fsize($2, 02);
    emit2(0170000|co_id);
    emit2(($3<<10)|($5<<7)|$1);
   }
 | FMONADIC fsize FPREG
   { check_fsize($2, 02);
    emit2(0170000|co_id);
    emit2(($3<<10)|($3<<7)|$1);
   }
 | FSINCOS fsize ea ',' FPREG ':' FPREG
   { emit2(0170000|co_id|mrg_2);
    emit2(0040000|($2<<10)|($7<<7)|$1|$5);
    ea_2(0200, 0x01);
   }
 | FSINCOS fsize FPREG ',' FPREG ':' FPREG
   { check_fsize($2, 02);
    emit2(0170000|co_id);
    emit2(($3<<10)|($7<<7)|$1|$5);
   }
 | FBCC expr
   { fbranch($1, $2);}
 | FDBCC DREG ',' expr
   { emit2(0170110|co_id|$2);
    emit2($1);
    $4.val -= DOTVAL;
    if (!((((($4.val) + 0x8000L) & ~0xFFFFL) == 0))) nofit();
    newrelo($4.typ, RELPC|RELO2|RELBR|RELWR);
    emit2(((int)($4.val) & 0xFFFF));
   }
 | FNOP
   { emit2(0170200|co_id);
    emit2(0);
   }
 | FSCC ea
   { emit2(0170100|co_id|mrg_2);
    emit2($1);
    ea_2(0000, 0x01|0x08);
   }
 | FTST fsize ea
   { emit2((0170000|co_id|mrg_2));
    emit2((0040072|($2<<10)));
    ch_sz_dreg($2, mrg_2&070);
    ea_2(0200, 0x01);
   }
 | FTST fsize FPREG
   { check_fsize($2, 02);
    emit2(0170000|co_id);
    emit2(($3<<10)|072);
   }
 | FSAVRES ea
   { if ((mrg_2&070) == ($1&070))
     badoperand();
    emit2((0170000|co_id|($1&0700)|mrg_2));
    ea_2(0, $1&07);
   }
 | FTRAPCC
   { emit2(0170174|co_id);
    emit2($1);
   }
 | FTRAPCC SIZE imm
   { checksize($2, 2|4);
    emit2((0170170|co_id|($2==0200?03:02)));
    emit2($1);
    ea_2($2,0);
   }
 ;
fregs : DREG
   { $$ = 04000 | $1 << 4; }
 | frlist
 ;
frlist : frrange
 | frlist '/' frrange
   { $$ = $1 | $3;}
 ;
frrange : FPREG
   { $$ = 1 << $1; }
 | FPREG '-' FPREG
   { if ($1 > $3)
     badoperand();
    for ($$ = 0; $1 <= $3; $1++)
     $$ |= (1 << $1);
   }
 ;
fcregs : FPCR
   { $$ = $1 << 10; }
 | fcregs '/' FPCR
   { $$ = $1 | ($3 << 10); }
 ;
fsize :
   { $$ = 02; }
 | SIZE
   { if ($1 == 0200)
     $$ = 00;
    else if ($1 == 0100)
     $$ = 04;
    else $$ = 06;
   }
 | FSIZE
 ;
%%
